$OpenBSD: patch-cmake_modules_FindLiboRTP_cmake,v 1.1.1.1 2013/12/08 18:39:44 zhuk Exp $
Rework oRTP library detection.
--- cmake/modules/FindLiboRTP.cmake.orig	Fri Jun 28 22:08:21 2013
+++ cmake/modules/FindLiboRTP.cmake	Mon Dec  2 17:34:54 2013
@@ -8,6 +8,8 @@
 
 INCLUDE( FindPackageHandleStandardArgs )
 include( FindPkgConfig )
+include( CMakePushCheckState )
+include( CheckCSourceRuns )
 
 SET( LIBORTP_FOUND FALSE )
 
@@ -23,30 +25,27 @@ FIND_LIBRARY( LIBORTP_LIBRARY
               PATHS ${ortp_LIBDIR}
 )
 
-IF( LIBORTP_INCLUDE_DIR AND LIBORTP_LIBRARY )
-  # we need to save and disable the C flags currently set, as they can conflict
-  # with ortp's requirements (c99)
-  set(save_cmake_c_flags ${CMAKE_C_FLAGS})
-  set(CMAKE_C_FLAGS)
-  try_run( run_result compile_result
-           ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ortpversion.c
-           CMAKE_FLAGS -DINCLUDE_DIRECTORIES:STRING=${LIBORTP_INCLUDE_DIR} -DLINK_LIBRARIES=${LIBORTP_LIBRARY}
-           COMPILE_DEFINITIONS "${ortp_CFLAGS}"
-           ARGS "0 13"
-  )
-  set(CMAKE_C_FLAGS ${save_cmake_c_flags})
+set(LIBORTP_LIBRARIES)
+set(LIBORTP_INCLUDE_DIRS)
+if(LIBORTP_INCLUDE_DIR AND LIBORTP_LIBRARY)
+  set(_LIBORTP_TEST_CODE "
+#include <ortp/ortp.h>
+int main() { return ortp_min_version_required(0, 13, 0) ? 0 : 1; }
+")
+  cmake_push_check_state(RESET)
+  set(CMAKE_REQUIRED_INCLUDES ${LIBORTP_INCLUDE_DIR} ${ortp_INCLUDE_DIRS})
+  set(CMAKE_REQUIRED_LIBRARIES ${LIBORTP_LIBRARY} ${ortp_LDFLAGS})
+  set(CMAKE_REQUIRED_FLAGS -std=gnu99)
+#  set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} ${ortp_CFLAGS})
+  check_c_source_runs("${_LIBORTP_TEST_CODE}" LiboRTP_VERSION_CHECK)
+  if(LiboRTP_VERSION_CHECK)
+    set(LIBORTP_LIBRARIES ${LIBORTP_LIBRARY})
+    set(LIBORTP_INCLUDE_DIRS ${LIBORTP_INCLUDE_DIR})
+  endif()
+  cmake_pop_check_state()
+endif()
 
-  if ( compile_result )
-    if ( run_result EQUAL 0 )
-#     Version OK
-      SET( LIBORTP_FOUND TRUE )
-      MESSAGE( STATUS "Found libortp: ${LIBORTP_LIBRARY}" )
-    endif ( run_result EQUAL 0 )
-  endif( compile_result )
-ENDIF( LIBORTP_INCLUDE_DIR AND LIBORTP_LIBRARY )
-
-if( NOT LIBORTP_FOUND )
-  if( LiboRTP_FIND_REQUIRED )
-    message( FATAL_ERROR "You need ortp, minimum version 0.13." )
-  endif ( LiboRTP_FIND_REQUIRED )
-endif( NOT LIBORTP_FOUND )
+find_package_handle_standard_args(LiboRTP
+                                  FOUND_VAR LIBORTP_FOUND
+                                  REQUIRED_VARS LIBORTP_LIBRARIES LIBORTP_INCLUDE_DIRS
+                                 )
